//01 给定一个无序整数数组，找出最长连续序列的长度 

function LongestConsecutive(nums){
    if(!nums){
        return console.log('数组为空，重新传递');
    }

    const numsSet = new Set(nums);
    let maxLength = 0;

    for(const num of numsSet){
        if(!numsSet.has(num-1)){
            
            let currentNum = num;
            let currentLength = 1;

            while(numsSet.has(currentNum+1)){
                currentNum++;
                currentLength++;
            }

            maxLength = Math.max(maxLength,currentLength);
            
        }
    }

    return maxLength;

}

console.log(LongestConsecutive([2,4,7,10,8,9,5,14,21,22]))